package cn.tedu.springboot01.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AroundTestAspect {

    @Around("bean(userServiceImpl)")
    public Object test(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            System.out.println("在目标方法执行之前");
            // 调用后续的目标业务方法
            Object result = joinPoint.proceed();
            System.out.println("在目标方法执行之后");
            return result;
        } catch (Exception e) {
            System.out.println("执行目标方法出现异常之后执行");
            throw e;
        } finally {
            System.out.println("执行目标方法不管是否出现异常都执行");
        }
    }

}
